﻿@using DIS.Infrastructure.Entities.Entity;
@{
    ViewBag.Title = "住宿费明细";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<FinancialPeriod> yearmonth = ViewBag.YearMonth;
    User user = ViewBag.User;
    HotelFee hotelfee = ViewBag.hotelfee;
    List<HotelFeeDetail> hotelFeeDetails = ViewBag.hotelFeeDetails;
    int hotelfeeId = hotelfee == null ? 0 : hotelfee.Id;
    List<Project> projects = ViewBag.projects;
}
@section head{
    <script type="text/javascript">
        
        

        function feesum() {
            var sumfee = 0;
            var sumDays = 0;

            $("input[id='CheckOutDate']").each(function () {
                var checkOutDate = $(this).val();
                var parentObj = $(this).parent().parent();
                var checkInDate = parentObj.find("input[id='CheckInDate']").val();
                var arrDate, objDate1, objDate2, intDays = 0, price = 0, money = 0;
                if (checkOutDate != "" && checkInDate != "") {


                    objDate1 = new Date();
                    objDate2 = new Date();

                    arrDate = checkInDate.split("-");
                    objDate1.setFullYear(arrDate[0], arrDate[1], arrDate[2]);

                    arrDate = checkOutDate.split("-");
                    objDate2.setFullYear(arrDate[0], arrDate[1], arrDate[2]);

                    intDays = parseInt(Math.abs(objDate1 - objDate2) / 1000 / 60 / 60 / 24);
                    intDays = intDays + 1;
                    parentObj.find("input[id='Days']").val(intDays);

                    sumDays = sumDays + intDays;

                    price = parentObj.find("input[id='Price']").val();
                    if (price != "") {
                        money = price * (intDays-1);
                         
                        parentObj.find("input[id='Totalmoney']").val(money);
                        sumfee = sumfee + money;

                    }
                }
               

            });
            
//            var sumfee = 0;
//            $("input[id='taxfee']").each(function () {
//                var fee = $(this).val();
//                sumfee = sumfee + fee * 1;
//            });
            $('#stotaldays').html(sumDays);
            $('#stotalfee').html(sumfee);
        }

        function invoicesum() {
            var sumcount = 0;
            $("input[id='invoicecount']").each(function () {
                var fee = $(this).val();
                sumcount = sumcount + fee * 1;
            });

            $('#stotalcount').html(sumcount);
        }

        function yearMonthSelect() {
            var obj = document.getElementById("selyearmonth");
            var date = obj.options[obj.selectedIndex].value;

            $('#fillDate').html("(" + date.split('$')[1] + ")");
        }
    </script>
}
<form name="saveuserForm" action="/Reimbursement/SaveHotelFee" method="post">

<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#D6D6D6">
    <tr>
        <td height="19" background="/content/img/tbg.gif" bgcolor="#E7E7E7">
            <table width="96%" border="0" cellspacing="1" cellpadding="1">
                <tr>
                    <td style="padding-left: 10px;">
                        <b><strong>住宿费明细</strong></b>
                    </td>
                    <td align="right">
                        <b><strong><a href="/Reimbursement/HotelFee">住宿费列表</a></strong></b>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td align="center" valign="top" bgcolor="#FFFFFF">
            <input type="hidden" id="issubmit" name="state" value="0" />
            <input type="hidden" id="MainId" name="MainId" value="@hotelfeeId" />
            <table width="98%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#D6D6D6">
                <tr height="30px">
                    <td colspan="7" align="left">
                        <strong>住宿费登记表</strong>&nbsp;&nbsp;<select name="selyearmonth" id="selyearmonth" onchange="yearMonthSelect()">
                            <option value="无">请选择</option>
                            @{
                                string filldate = "";
                                if (yearmonth != null && yearmonth.Any())
                                {
                                    foreach (var item in yearmonth)
                                    {
                                        string sdateStr = DateTime.Parse(item.StartDate).ToString("yyyy年MM月dd日");
                                        string edateStr = DateTime.Parse(item.EndDate).ToString("yyyy年MM月dd日");

                                        if (hotelfee != null && hotelfee.Year == item.Year && hotelfee.Month == item.Month)
                                        {
                                            filldate = "(" + sdateStr + "-" + edateStr + ")";
                                <option value="@(item.Year):@(item.Month):@(item.StartDate):@(item.EndDate)$@(sdateStr)-@(edateStr)" selected>@item.Year-@item.Month</option>
                                        }
                                        else
                                        {
                                <option value="@(item.Year):@(item.Month):@(item.StartDate):@(item.EndDate)$@(sdateStr)-@(edateStr)">@item.Year-@item.Month</option>
                                        }
                                    }
                                }
                            }
                        </select><span id="fillDate">@filldate</span>&nbsp;&nbsp;&nbsp;&nbsp;
                        <strong>项目名称</strong>&nbsp;&nbsp;<select name="projectId" id="projectId">
                        <option value="0">请选择</option>
                        @{
                            if(projects!=null&&projects.Count>0)
                            {
                                foreach(var item in projects)
                                {
                                    if (hotelfee != null&&hotelfee.project.Id==item.Id)
                                    {
                                        <option value="@item.Id" selected>@item.ProjectCode (@item.ProjectName)</option>
                                    }
                                    else
                                    {
                                    <option value="@item.Id">@item.ProjectCode (@item.ProjectName)</option>
                                    }
                                }
                            }
                        }
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="11">
                        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
                             <thead>
                                <tr  bgcolor="#FBFCE2">
                                 <td width="8%" height="30" align="center" rowspan="2">
                                        专业所
                                    </td>
                                    <td width="8%" height="30" align="center"  rowspan="2">
                                        姓名
                                    </td>
                                    <td width="29%" height="30" align="center" colspan="3">
                                        出差时间
                                    </td>
                                    <td width="10%" height="30" align="center"  rowspan="2">
                                        出差地点
                                    </td>
                                    <td width="15%" height="30" align="center"  rowspan="2">
                                        入住酒店
                                    </td>
                                    <td width="8%" height="30" align="center"  rowspan="2">
                                        单价
                                    </td>
                                    <td width="8%" height="30" align="center"  rowspan="2">
                                        住宿费
                                    </td>
                                    <td width="8%" height="30" align="center"  rowspan="2">
                                        发票数
                                    </td>
                                    <td width="5%" height="30" align="center"  rowspan="2">
                                    </td>
                                </tr>
                                <tr bgcolor="#FBFCE2">
                                <td width="12%" align="center">起</td>
                                 <td width="12%" align="center">止</td>
                                  <td width="5%" align="center">天</td>
                                </tr>
                            </thead>
                            <tbody>
                                @{
                                    if (hotelFeeDetails != null && hotelFeeDetails.Count > 0)
                                    {
                                        int j = 0;
                                        foreach (var item in hotelFeeDetails)
                                        {
                                              <tr bgcolor="#FFFFFF" align="center">
                                                 <td width="8%" height="30" align="center">@user.ProfessionName</td>
                                                <td width="8%" height="30" align="center">@user.RealName</td>
                                                <td align="center">
                                                    <input  name="CheckInDate" id="CheckInDate" value="@item.CheckInDate" type="text" onchange="feesum()"  onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" style="width: 90%" />
                                                </td>
                                                 <td align="center">
                                                    <input  name="CheckOutDate" id="CheckOutDate" value="@item.CheckOutDate" type="text" onchange="feesum()"  onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" style="width: 90%" />
                                                </td>
                                                <td align="center">
                                                    <input type="text" name="Days" value="@item.Days" disabled=disabled id="Days" style="width: 80%"  />
                                                </td>
                                                <td align="center">
                                                    <input type="text" name="TravelAddress" value="@item.TravelAddress" id="TravelAddress" style="width: 90%"  />
                                                </td>
                                                <td align="center">
                                                    <input name="HotelName" type="text" value="@item.HotelName" id="HotelName" style="width: 90%" />
                                                </td>
                                                <td align="center">
                                                    <input  name="Price" type="text" value="@item.Price" id="Price" onkeyup="feesum()"  style="width: 90%" />
                                                </td>
                                                <td align="center">
                                                    <input  name="TotalFee" type="text" value="@item.TotalFee" disabled="disabled" id="Totalmoney"  style="width: 90%" />
                                                </td>
                                                <td align="center">
                                                    <input  name="invoicecount" type="text" value="@item.InvoiceCount" id="invoicecount" onkeyup="invoicesum()" style="width: 90%" />
                                                </td>
                                                <td align="center">
                                                    @{if (j == 0)
                                                      {
                                                    <a href="javascript:;" class="addTr">[+]</a>
                                                      }
                                                      else
                                                      {
                                                          <a href="javascript:;" class="removeTr">[-]</a>
                                                      }

                                                    }
                                                </td>
                                            </tr>
                                                      j++;
                                        }
                                    }
                                    else
                                    {
                                        <tr bgcolor="#FFFFFF" align="center" >
                                                <td width="8%" height="30" align="center">@user.ProfessionName</td>
                                                    <td width="8%" height="30" align="center">@user.RealName</td>
                                                    <td width="12%" align="center">
                                                        <input  name="CheckInDate" id="CheckInDate" value="" type="text"  onchange="feesum()" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'});" style="width: 90%" />
                                                    </td>
                                                     <td width="12%" align="center">
                                                        <input  name="CheckOutDate" id="CheckOutDate" value="" type="text" onchange="feesum()" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" style="width: 90%" />
                                                    </td>
                                                    <td width="5%" align="center">
                                                        <input type="text" name="Days" value="" disabled=disabled id="Days" style="width: 80%"  />
                                                    </td>
                                                    <td width="10%" align="center">
                                                        <input type="text" name="TravelAddress" value="" id="TravelAddress" style="width: 90%"  />
                                                    </td>
                                                    <td width="15%" align="center">
                                                        <input name="HotelName" type="text" value="" id="HotelName" style="width: 90%" />
                                                    </td>
                                                     <td width="8%" align="center">
                                                        <input  name="Price" type="text" value="" id="Price" onkeyup="feesum()" style="width: 90%" />
                                                    </td>
                                                    <td width="8%" align="center">
                                                        <input  name="TotalFee" type="text" value="" disabled="disabled"  id="Totalmoney" style="width: 90%" />
                                                    </td>
                                                    <td width="8%" align="center">
                                                        <input  name="invoicecount" type="text" value="" id="invoicecount" onkeyup="invoicesum()" style="width: 90%" />
                                                    </td>
                                                <td width="5%" align="center">
                                                    <a href="javascript:;" class="addTr">[+]</a>
                                                </td>
                                      </tr>
                                    }
                                }
                                
                            </tbody>
                            <tfoot>
                             <tr bgcolor="#FBFCE2" align="center" class="hover">
                    <td width="8%" align="center">
                        <font><b>合计</b></font>
                    </td>
                    <td width="8%">
                        &nbsp;
                    </td>
                    <td width="12%">
                        &nbsp;
                    </td>
                     <td width="12%">
                        &nbsp;
                    </td>
                     <td width="5%">
                        @{
                            if (hotelfee != null)
                            {
                                <span name="stotaldays" id="stotaldays" value="0">@hotelfee.TotalDays</span>
                            }
                            else
                            {
                                <span name="stotaldays" id="stotaldays" value="0">0</span>
                            }
                       }
                    </td>
                    <td width="10%">
                        &nbsp;
                    </td>
                    <td width="15%">
                        &nbsp;
                    </td>
                    <td width="8%">
                        &nbsp;
                    </td>
                    
                    <td width="8%">
                    @{
                        if (hotelfee != null)
                        {
                                <span name="stotalfee" id="stotalfee" value="0">@hotelfee.TotalFee</span>
                        }
                        else
                        {
                                <span name="stotalfee" id="stotalfee" value="0">0.00</span>
                        }
                       }
                    </td>
                    <td width="8%">
                    @{
                        if (hotelfee != null)
                        {
                            <span name="stotalcount" id="stotalcount" value="0">@hotelfee.InvoiceCount</span>
                        }
                        else
                        {
                            <span name="stotalcount" id="stotalcount" value="0">0</span>
                        }
                        }
                        
                    </td>
                    <td width="5%">
                        &nbsp;
                    </td>
                </tr>
                            </tfoot>
                        </table>
                    </td>
                </tr>
               
                <tr bgcolor="#FFFFFF" align="center" class="hover">
                    <td align="left" colspan="11">
                        <b><font style="color: red">说明：本表作为每月报销差旅费附件。</font></b>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td align="center">
            <input class="new_save" value="保存" type="Submit" />
            <input class="new_submit" value="提交" type="Submit" />
        </td>
    </tr>
</table>
<span id="moban" style="display:none"><tr bgcolor="#FFFFFF" align="center" >
                                     <td width="8%" height="30" align="center">@user.ProfessionName</td>
                                                    <td width="8%" height="30" align="center">@user.RealName</td>
                                                    <td width="12%" align="center">
                                                        <input  name="CheckInDate" id="CheckInDate" value="" type="text"  onchange="feesum()" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" style="width: 90%" />
                                                    </td>
                                                     <td width="12%" align="center">
                                                        <input  name="CheckOutDate" id="CheckOutDate" value="" type="text"  onchange="feesum()" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" style="width: 90%" />
                                                    </td>
                                                    <td width="5%" align="center">
                                                        <input type="text" name="Days" value="" disabled=disabled id="Days" style="width: 80%"  />
                                                    </td>
                                                    <td width="10%" align="center">
                                                        <input type="text" name="TravelAddress" value="" id="TravelAddress" style="width: 90%"  />
                                                    </td>
                                                    <td width="15%" align="center">
                                                        <input name="HotelName" type="text" value="" id="HotelName" style="width: 90%" />
                                                    </td>
                                                     <td width="8%" align="center">
                                                        <input  name="Price" type="text" value="" id="Price" onkeyup="feesum()" style="width: 90%" />
                                                    </td>
                                                    <td width="8%" align="center">
                                                        <input  name="TotalFee" type="text" value="" id="Totalmoney" disabled=disabled  style="width: 90%" />
                                                    </td>
                                                    <td width="8%" align="center">
                                                        <input  name="invoicecount" type="text" value="" id="invoicecount" onkeyup="invoicesum()" style="width: 90%" />
                                                    </td>
                                    <td align="center">
                                        <a href="javascript:;" class="removeTr">[-]</a>
                                    </td>
                                </tr></span>
</form>
@section tail{
    <script type="text/javascript">
        $('.addTr').live('click', function () {

            str = $(this).parent().parent().html();
            str = str.replace('addTr', 'removeTr');
            str = str.replace('[+]', '[-]');
           // str = $("#moban").html();
            $(this).parent().parent().parent().append('<tr  bgcolor="#FFFFFF">' + str + '</tr>');
            //$(this).parent().parent().parent().append(str);
            feesum();
            invoicesum();
        });

        $('.removeTr').live('click', function () {
            $(this).parent().parent().remove();
            feesum();
            invoicesum();
            return false;
        });
        $('.new_save').click(function () {
            $('#issubmit').attr('value', 0);
            return true;
        });
        $('.new_submit').click(function () {
            $('#issubmit').attr('value', 1);
            return true;
        });
        
    </script>
}
